package nl.tudelft.jpacman.level;

import nl.tudelft.jpacman.npc.Ghost;
import nl.tudelft.jpacman.points.PointCalculator;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.DisplayName;
import org.junit.jupiter.api.Test;

import static org.mockito.Mockito.*;

class PlayerCollisionsTest {
    private PlayerCollisions playerCollisions;
    private PointCalculator pointCalculator;

    @BeforeEach
    void setup() {
        pointCalculator = mock(PointCalculator.class);
        playerCollisions = new PlayerCollisions(pointCalculator);
    }

    @Test
    @DisplayName("Player移动到Ghost")
    void playerCollideOnGhost() {
        //arrange
        Player player = mock(Player.class);
        Ghost ghost = mock(Ghost.class);
        //act
        playerCollisions.collide(player, ghost);
        //assert
        verify(pointCalculator).collidedWithAGhost(player, ghost);
        verify(player).setAlive(false);
        verify(player).setKiller(ghost);
    }

    @Test
    @DisplayName("Player移动到Pellet")
    void playerCollideOnPellet() {
        //arrange
        Player player = mock(Player.class);
        Pellet pellet = mock(Pellet.class);
        //act
        playerCollisions.collide(player, pellet);
        //assert
        verify(pointCalculator).consumedAPellet(player, pellet);//到豆子得分
        verify(pellet).leaveSquare();
    }

    @Test
    @DisplayName("Ghost移动到Player")
    void ghostCollideOnPlayer() {
        //arrange
        Player player = mock(Player.class);
        Ghost ghost = mock(Ghost.class);
        //act
        playerCollisions.collide(ghost, player);
        //assert
        verify(pointCalculator).collidedWithAGhost(player, ghost);
        verify(player).setAlive(false);
        verify(player).setKiller(ghost);
    }

    @Test
    @DisplayName("Ghost移动到Pellet")//什么都没发生
    void ghostCollideOnPellet() {
        //arrange
        Ghost ghost = mock(Ghost.class);
        Pellet pellet = mock(Pellet.class);
        //act
        playerCollisions.collide(ghost, pellet);
        //assert
        verifyNoInteractions(ghost, pellet);
    }

    @Test
    @DisplayName("ghost1移动到ghost2")//什么都没发生

    void ghost1CollideOnGhost2() {
        Ghost ghost1 = mock(Ghost.class);
        Ghost ghost2 = mock(Ghost.class);
        playerCollisions.collide(ghost1, ghost2);
        verifyNoInteractions(ghost1, ghost2);
    }

}
